#include <stdio.h>
#include <stdlib.h>
#include <allegro.h>
#include "fonction.h"

int main() {
  
  
	char buf[50];
	BITMAP *Buffer;	
        weapon fl ;
	weapon fl1 ;
        BITMAP *Background;
	PERSO perso;
	PERSO perso1;	
	int i,m,f,c;
int valid; int valid1;
int compteur1 ;
int compteur2;	
 compteur1 = 0;
	//soundm(&sound);
	/* General initialization function */
	allegro_init();
	if(install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT,NULL)){
allegro_message("sound error :%s",allegro_error);
return 1;}
	if (install_keyboard() == -1) {
		allegro_message("Error! %s", allegro_error);
		return -1;
	}
	set_color_depth(16);
	if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 1200,700, 0, 0) != 0) {
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); /* here’s the command for text mode */
		allegro_message("Unable to initialize video mode!\n%s\n", allegro_error);
		return 1;
	}
	Buffer = create_bitmap(SCREEN_W, SCREEN_H);
        perso.bg=load_bitmap("/home/nizar/Desktop/jeux/Untitled-0.bmp", NULL);	


//loading perso
load_hamma(&perso ,buf);
load_abu(&perso1,buf);
load_flip (&fl1,&fl);

//init position & direction  
init_hamma (&perso);
init_abu (&perso1);



        while (!key[KEY_ESC]) 
{
while (perso.vie>0 && perso1.vie>0){
		//vider le buffer
		clear_bitmap(Buffer);


		draw_sprite(Buffer, perso.bg,  0, 0);
		/*if(perso.y != (SCREEN_H / 2)+160)
		(perso.y)+=70;*/
		
		move_perso(&perso,&compteur1,&perso1,&compteur2);
 		//valid = ymes_abu(&perso1,&fl);
		//valid1 = ymes_abu(&perso,&fl1);
/*if (valid==0)
		{tir_hamma (&fl,&perso,Buffer);}
if (valid1==0)
		{tir_abu(&perso1,&fl1,Buffer);}
 		
                draw_hamma(Buffer,fl,perso,m,compteur1);
		draw_abu(Buffer,fl1,perso1,f,compteur2);
                gravitee(&perso,&perso1);*/

		
blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
		
		
}
//destroy sprites
	
Background = load_bitmap("JIJI.bmp",NULL);
clear_bitmap(screen);
draw_sprite (screen,Background,SCREEN_W/4,SCREEN_H/2);readkey();
//textprintf_centre_ex(screen,font,SCREEN_W/2,120,makecol(255,0,0),-1,"GAME OVER");readkey();
//draw_sprite(gameover,screen,300,300);
}
for (i = 0; i < NB_IMAGES; i++) {
		destroy_bitmap(perso1.img_right[i]);
		destroy_bitmap(perso1.img_left[i]);
	}
	destroy_bitmap(Buffer);
	return 0;

}
END_OF_MAIN();
